summaryrefslogtreecommitdiff
path: root/modules/server_add
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-03-04 15:46:10 +0000
committerTim Almdal <tnalmdal@shaw.ca>2009-03-04 15:46:10 +0000
commitf7d82ec52f533c620c94fe0327175747cc3d8877 (patch)
treea4fdc5d31e700036083e11f31f17c8fca6cccd60 /modules/server_add
parentf16224ae828e43204cf334681941c27f179e09c3 (diff)
Rename local_import module to server_add
Diffstat (limited to 'modules/server_add')
-rw-r--r--modules/server_add/controllers/admin_server_add.php94
-rw-r--r--modules/server_add/controllers/server_add.php128
-rw-r--r--modules/server_add/css/admin.css29
-rw-r--r--modules/server_add/css/jquery.autocomplete.css49
-rw-r--r--modules/server_add/css/server_add.css60
-rw-r--r--modules/server_add/helpers/server_add_block.php30
-rw-r--r--modules/server_add/helpers/server_add_installer.php47
-rw-r--r--modules/server_add/helpers/server_add_menu.php43
-rw-r--r--modules/server_add/helpers/server_add_theme.php38
-rw-r--r--modules/server_add/js/admin.js47
-rw-r--r--modules/server_add/js/jquery.autocomplete.pack.js13
-rw-r--r--modules/server_add/js/server_add.js131
-rw-r--r--modules/server_add/module.info3
-rw-r--r--modules/server_add/views/server_add_admin.html.php10
-rw-r--r--modules/server_add/views/server_add_dir_list.html.php13
-rw-r--r--modules/server_add/views/server_add_tree.html.php22
-rw-r--r--modules/server_add/views/server_add_tree_dialog.html.php26
17 files changed, 783 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 00000000..a340f61a
--- /dev/null
+++ b/modules/server_add/controllers/admin_server_add.php
@@ -0,0 +1,94 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 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->content = new View("server_add_admin.html");
+ $view->content->add_form = $this->_get_admin_form();
+ $view->content->path_list = new View("server_add_dir_list.html");
+ $paths = unserialize(module::get_var("server_add", "authorized_paths", "a:0:{}"));
+ $view->content->path_list->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()) {
+ if (is_readable($form->add_path->path->value)) {
+ $paths[$form->add_path->path->value] = 1;
+ module::set_var("server_add", "authorized_paths", serialize($paths));
+ $view = new View("server_add_dir_list.html");
+ $view->paths = array_keys($paths);
+ $form->add_path->inputs["path"]->value("");
+ print json_encode(
+ array("result" => "success",
+ "paths" => $view->__toString(),
+ "form" => $form->__toString()));
+ } else {
+ $form->add_path->inputs["path"]->error("not_readable");
+ print json_encode(array("result" => "error", "form" => $form->__toString()));
+ }
+ } else {
+ print json_encode(array("result" => "error", "form" => $form->__toString()));
+ }
+
+ }
+
+ public function remove_path() {
+ access::verify_csrf();
+
+ $path = $this->input->post("path");
+ $paths = unserialize(module::get_var("server_add", "authorized_paths"));
+ unset($paths[$path]);
+ module::set_var("server_add", "authorized_paths", serialize($paths));
+
+ $view = new View("server_add_dir_list.html");
+ $view->paths = array_keys($paths);
+
+ print $view;
+ }
+
+ public function autocomplete() {
+ $directories = array();
+ $path_prefix = $this->input->get("q");
+ foreach (glob("{$path_prefix}*") as $file) {
+ if (is_dir($file)) {
+ $directories[] = $file;
+ }
+ }
+
+ print implode("\n", $directories);
+ }
+
+ private function _get_admin_form() {
+ $form = new Forge("admin/server_add/add_path", "", "post",
+ array("id" => "gServerAddAdminForm"));
+ $add_path = $form->group("add_path");
+ $add_path->input("path")->label(t("Path"))->rules("required")
+ ->error_messages("not_readable", t("The directory is not readable by the webserver"));
+ $add_path->submit("add")->value(t("Add Path"));
+
+ return $form;
+ }
+} \ No newline at end of file
diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php
new file mode 100644
index 00000000..f269e3f9
--- /dev/null
+++ b/modules/server_add/controllers/server_add.php
@@ -0,0 +1,128 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 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 Controller {
+ public function index($id) {
+ $paths = unserialize(module::get_var("server_add", "authorized_paths"));
+
+ $item = ORM::factory("item", $id);
+ access::required("server_add", $item);
+
+ $view = new View("server_add_tree_dialog.html");
+ $view->action = url::site("server_add/add_photo/$id");
+ $view->hidden = array("csrf" => access::csrf_token(), "base_url" => url::base(true));
+ $view->parents = $item->parents();
+ $view->album_title = $item->title;
+
+ $tree = new View("server_add_tree.html");
+ $tree->data = array();
+ $tree->uid = "tree_$id";
+ foreach (array_keys($paths) as $path) {
+ $tree->data[$path] = array("path" => $path, "is_dir" => true);
+ }
+ $view->tree = $tree->__toString();
+ print $view;
+ }
+
+ public function children() {
+ $path = $this->input->post("path");
+ $path = implode("/", $this->input->post("path"));
+ if (!is_readable($path)) {
+ kohana::show_404();
+ }
+
+ $tree = new View("server_add_tree.html");
+ $tree->data = $this->_get_children($path);
+ $tree->uid = "tree_" . md5($path);
+ print $tree;
+ }
+
+ function start() {
+ batch::start();
+ }
+
+ function add_photo($id) {
+ access::verify_csrf();
+
+ $parent = ORM::factory("item", $id);
+ access::required("server_add", $parent);
+ if (!$parent->is_album() && !$parent->loaded ) {
+ throw new Exception("@todo BAD_ALBUM");
+ }
+
+ $path = $this->input->post("path");
+
+ $paths = unserialize(module::get_var("server_add", "authorized_paths"));
+ if (empty($paths[$path[0]])) {
+ throw new Exception("@todo BAD_PATH");
+ }
+
+ $source_path = $path[0];
+ // The first path corresponds to the source directory so we can just skip it.
+ for ($i = 1; $i < count($path); $i++) {
+ $source_path .= "/$path[$i]";
+ $pathinfo = pathinfo($source_path);
+ set_time_limit(30);
+ if (is_dir($source_path)) {
+ $album = ORM::factory("item")
+ ->where("name", $path[$i])
+ ->where("parent_id", $parent->id)
+ ->find();
+ if (!$album->loaded) {
+ $album = album::create($parent, $path[$i], $path[$i], null, user::active()->id);
+ }
+ $parent = $album;
+ } else if (in_array($pathinfo["extension"], array("flv", "mp4"))) {
+ $movie = movie::create($parent, $source_path, basename($source_path),
+ basename($source_path), null, user::active()->id);
+ } else {
+ $photo = photo::create($parent, $source_path, basename($source_path),
+ basename($source_path), null, user::active()->id);
+ }
+ }
+ }
+
+ public function finish() {
+ batch::stop();
+ print json_encode(array("result" => "success"));
+ }
+
+ private function _get_children($path) {
+ $file_list = array();
+ $files = new DirectoryIterator($path);
+ foreach ($files as $file) {
+ if ($file->isDot()) {
+ continue;
+ }
+ $filename = $file->getFilename();
+ if ($filename[0] != ".") {
+ if ($file->isDir()) {
+ $file_list[$filename] = array("path" => $file->getPathname(), "is_dir" => true);
+ } else {
+ $extension = strtolower(substr(strrchr($filename, '.'), 1));
+ if ($file->isReadable() &&
+ in_array($extension, array("gif", "jpeg", "jpg", "png", "flv", "mp4"))) {
+ $file_list[$filename] = array("path" => $file->getPathname(), "is_dir" => false);
+ }
+ }
+ }
+ }
+ return $file_list;
+ }
+} \ No newline at end of file
diff --git a/modules/server_add/css/admin.css b/modules/server_add/css/admin.css
new file mode 100644
index 00000000..b700919b
--- /dev/null
+++ b/modules/server_add/css/admin.css
@@ -0,0 +1,29 @@
+#gServerAddAdmin {
+ margin:auto;
+ text-align: left;
+}
+
+#gServerAddAdmin form fieldset {
+ border: medium none;
+}
+
+#gServerAddAdmin legend {
+ display: none;
+}
+
+#gServerAddAdmin .gWarning {
+ background-color: #FFFF99;
+}
+
+#gAuthorizedPath {
+ margin: 0 !important;
+ padding: 0.3em 1.5em 0.3em 1em;
+}
+
+#gServerAdd Admin #path {
+ width: 80%;
+}
+
+.gRemoveDir:hover {
+ cursor: pointer;
+}
diff --git a/modules/server_add/css/jquery.autocomplete.css b/modules/server_add/css/jquery.autocomplete.css
new file mode 100644
index 00000000..4d50cf43
--- /dev/null
+++ b/modules/server_add/css/jquery.autocomplete.css
@@ -0,0 +1,49 @@
+.ac_results {
+ padding: 0px;
+ border: 1px solid black;
+ background-color: white;
+ overflow: hidden;
+ text-align: left;
+ z-index: 99999;
+}
+
+.ac_results ul {
+ width: 100%;
+ list-style-position: outside;
+ list-style: none;
+ padding: 0;
+ margin: 0;
+}
+
+.ac_results li {
+ margin: 0px;
+ padding: 2px 5px;
+ cursor: default;
+ display: block;
+ /*
+ if width will be 100% horizontal scrollbar will apear
+ when scroll mode will be used
+ */
+ /*width: 100%;*/
+ font: menu;
+ font-size: 12px;
+ /*
+ it is very important, if line-height not setted or setted
+ in relative units scroll will be broken in firefox
+ */
+ line-height: 16px;
+ overflow: hidden;
+}
+
+.ac_loading {
+ background: white url('indicator.gif') right center no-repeat;
+}
+
+.ac_odd {
+ background-color: #eee;
+}
+
+.ac_over {
+ background-color: #0A246A;
+ color: white;
+}
diff --git a/modules/server_add/css/server_add.css b/modules/server_add/css/server_add.css
new file mode 100644
index 00000000..16ccc539
--- /dev/null
+++ b/modules/server_add/css/server_add.css
@@ -0,0 +1,60 @@
+.gCheckboxTree {
+ display: none;
+}
+
+.gCheckboxTree input {
+ display: inline;
+}
+
+.gCheckboxTree li {
+ padding: 0;
+ float: none;
+}
+
+.gCheckboxTree .ui-icon {
+ cursor: pointer;
+}
+
+.gFile {
+ padding-left: 2.5em;
+}
+
+#gProgressBar {
+ visibility: hidden;
+ height: 1em;
+ width: 100%;
+ margin-top: 0.5em;
+ display: inline-block;
+}
+
+#gServerAdd #gServerAddTree {
+ border: 1px solid #CCCCCC;
+ height: 25em;
+ overflow: auto;
+ margin-bottom: .5em;
+ padding-top: .5em;
+ padding-bottom: .5em;
+}
+
+#gServerAdd ul ul li {
+ padding-left: 1.2em;
+}
+
+#gServerAdd ul li .gFile {
+ padding-left: 2.5em;
+}
+
+#gServerAdd .gBreadcrumbs {
+ font-size: 1em;
+ padding: 0;
+ margin: 0;
+ border-top-width: 0px;
+}
+
+#gServerAdd p {
+ margin: 0;
+}
+
+#gServerAdd .gBreadcrumbs li {
+ padding: 10px 6px 10px 16px;
+}
diff --git a/modules/server_add/helpers/server_add_block.php b/modules/server_add/helpers/server_add_block.php
new file mode 100644
index 00000000..c2a94e97
--- /dev/null
+++ b/modules/server_add/helpers/server_add_block.php
@@ -0,0 +1,30 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 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_block_Core {
+ static function head($theme) {
+ $head[] = html::script("modules/server_add/js/server_add.js");
+
+ $url = url::file("modules/server_add/css/server_add.css");
+ $head[] = "<link rel=\"stylesheet\" type=\"text/css\" href=\"$url\" " .
+ "media=\"screen,print,projection\" />";
+
+ return implode("\n", $head);
+ }
+}
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 00000000..8b1c4688
--- /dev/null
+++ b/modules/server_add/helpers/server_add_installer.php
@@ -0,0 +1,47 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 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();
+ $version = module::get_version("server_add");
+ if ($version == 0) {
+ access::register_permission("server_add", t("Add files from server"));
+
+ access::allow(user::lookup(2), "view", ORM::factory("item", 1));
+
+ module::set_version("server_add", 1);
+ module::set_var("server_add", "authorized_paths", serialize(array()));
+ message::warning(
+ t("You have no upload directories, click <a href='%url'>here</a> to configure one",
+ array("url" => url::site("/admin/server_add"))));
+ }
+ }
+
+ static function uninstall() {
+ access::delete_permission("server_add");
+ $module = module::get("server_add");
+
+ $db = Database::instance();
+ $db->delete("vars", array("module_name" => $module->name));
+
+ module::delete("local_import");
+ module::delete("server_add");
+ }
+}
diff --git a/modules/server_add/helpers/server_add_menu.php b/modules/server_add/helpers/server_add_menu.php
new file mode 100644
index 00000000..fe27d6d2
--- /dev/null
+++ b/modules/server_add/helpers/server_add_menu.php
@@ -0,0 +1,43 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 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_menu_Core {
+ static function admin($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, $theme) {
+ $item = $theme->item();
+
+ $paths = unserialize(module::get_var("server_add", "authorized_paths"));
+
+ if ($item && access::can("edit", $item) && access::can("server_add", $item) &&
+ $item->is_album() && !empty($paths)) {
+ $options_menu = $menu->get("options_menu")
+ ->append(Menu::factory("dialog")
+ ->id("server_add")
+ ->label(t("Add from server"))
+ ->url(url::site("server_add/index/$item->id")));
+ }
+ }
+}
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 00000000..82c9a951
--- /dev/null
+++ b/modules/server_add/helpers/server_add_theme.php
@@ -0,0 +1,38 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 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 admin_head($theme) {
+ $head = array();
+ if (Router::$current_uri == "admin/server_add") {
+ $head[] = "<link media=\"screen, projection\" rel=\"stylesheet\" type=\"text/css\" href=\"" .
+ url::file("modules/server_add/css/jquery.autocomplete.css") . "\" />";
+ $head[] = "<link media=\"screen, projection\" rel=\"stylesheet\" type=\"text/css\" href=\"" .
+ url::file("modules/server_add/css/admin.css") . "\" />";
+ $base = url::base(true);
+ $csrf = access::csrf_token();
+ $head[] = "<script> var base_url = \"$base\"; var csrf = \"$csrf\";</script>";
+
+ $head[] = html::script("modules/server_add/js/jquery.autocomplete.pack.js");
+ $head[] = html::script("modules/server_add/js/admin.js");
+ }
+
+ return implode("\n", $head);
+ }
+} \ No newline at end of file
diff --git a/modules/server_add/js/admin.js b/modules/server_add/js/admin.js
new file mode 100644
index 00000000..dcd0dde0
--- /dev/null
+++ b/modules/server_add/js/admin.js
@@ -0,0 +1,47 @@
+/**
+ * Set up autocomplete on the server path list
+ *
+ */
+$("document").ready(function() {
+ add_autocomplete();
+ ajaxify_add_form();
+ add_onclick();
+});
+
+function add_autocomplete() {
+ $("#gServerAddAdmin input:text").autocomplete(base_url + "admin/server_add/autocomplete", {
+ extraParams: {csrf: csrf},
+ mustMatch: true,
+ max: 256});
+}
+function ajaxify_add_form(options) {
+ $("#gServerAddAdmin form").ajaxForm({
+ dataType: "json",
+ success: function(data) {
+ if (data.form) {
+ $("#gServerAddAdmin form").replaceWith(data.form);
+ ajaxify_add_form();
+ add_autocomplete();
+ }
+ if (data.result == "success") {
+ $("#gNoAuthorizedPaths").css("display", "none");
+ $("#gAuthorizedPath").html(data.paths);
+ add_onclick();
+ }
+ }
+ });
+}
+
+function add_onclick() {
+ $(".gRemoveDir").click(function() {
+ var parent = $(this).parent();
+ $.post(
+ base_url + "admin/local_import/remove_path",
+ {csrf: csrf,
+ path: parent.text().replace(/^\s\s*/, "").replace(/\s\s*$/, "")},
+ function(data, textStatus) {
+ $("#gAuthorizedPath").html(data);
+ add_onclick();
+ });
+ });
+}
diff --git a/modules/server_add/js/jquery.autocomplete.pack.js b/modules/server_add/js/jquery.autocomplete.pack.js
new file mode 100644
index 00000000..271014a2
--- /dev/null
+++ b/modules/server_add/js/jquery.autocomplete.pack.js
@@ -0,0 +1,13 @@
+/*
+ * Autocomplete - jQuery plugin 1.0.2
+ *
+ * Copyright (c) 2007 Dylan Verheul, Dan G. Switzer, Anjesh Tuladhar, Jörn Zaefferer
+ *
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ *
+ * Revision: $Id: jquery.autocomplete.js 5747 2008-06-25 18:30:55Z joern.zaefferer $
+ *
+ */
+eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}(';(3($){$.31.1o({12:3(b,d){5 c=Y b=="1w";d=$.1o({},$.D.1L,{11:c?b:14,w:c?14:b,1D:c?$.D.1L.1D:10,Z:d&&!d.1x?10:3U},d);d.1t=d.1t||3(a){6 a};d.1q=d.1q||d.1K;6 I.K(3(){1E $.D(I,d)})},M:3(a){6 I.X("M",a)},1y:3(a){6 I.15("1y",[a])},20:3(){6 I.15("20")},1Y:3(a){6 I.15("1Y",[a])},1X:3(){6 I.15("1X")}});$.D=3(o,r){5 t={2N:38,2I:40,2D:46,2x:9,2v:13,2q:27,2d:3x,2j:33,2o:34,2e:8};5 u=$(o).3f("12","3c").P(r.24);5 p;5 m="";5 n=$.D.2W(r);5 s=0;5 k;5 h={1z:B};5 l=$.D.2Q(r,o,1U,h);5 j;$.1T.2L&&$(o.2K).X("3S.12",3(){4(j){j=B;6 B}});u.X(($.1T.2L?"3Q":"3N")+".12",3(a){k=a.2F;3L(a.2F){Q t.2N:a.1d();4(l.L()){l.2y()}A{W(0,C)}N;Q t.2I:a.1d();4(l.L()){l.2u()}A{W(0,C)}N;Q t.2j:a.1d();4(l.L()){l.2t()}A{W(0,C)}N;Q t.2o:a.1d();4(l.L()){l.2s()}A{W(0,C)}N;Q r.19&&$.1p(r.R)==","&&t.2d:Q t.2x:Q t.2v:4(1U()){a.1d();j=C;6 B}N;Q t.2q:l.U();N;3A:1I(p);p=1H(W,r.1D);N}}).1G(3(){s++}).3v(3(){s=0;4(!h.1z){2k()}}).2i(3(){4(s++>1&&!l.L()){W(0,C)}}).X("1y",3(){5 c=(1n.7>1)?1n[1]:14;3 23(q,a){5 b;4(a&&a.7){16(5 i=0;i<a.7;i++){4(a[i].M.O()==q.O()){b=a[i];N}}}4(Y c=="3")c(b);A u.15("M",b&&[b.w,b.H])}$.K(1g(u.J()),3(i,a){1R(a,23,23)})}).X("20",3(){n.18()}).X("1Y",3(){$.1o(r,1n[1]);4("w"2G 1n[1])n.1f()}).X("1X",3(){l.1u();u.1u();$(o.2K).1u(".12")});3 1U(){5 b=l.26();4(!b)6 B;5 v=b.M;m=v;4(r.19){5 a=1g(u.J());4(a.7>1){v=a.17(0,a.7-1).2Z(r.R)+r.R+v}v+=r.R}u.J(v);1l();u.15("M",[b.w,b.H]);6 C}3 W(b,c){4(k==t.2D){l.U();6}5 a=u.J();4(!c&&a==m)6;m=a;a=1k(a);4(a.7>=r.22){u.P(r.21);4(!r.1C)a=a.O();1R(a,2V,1l)}A{1B();l.U()}};3 1g(b){4(!b){6[""]}5 d=b.1Z(r.R);5 c=[];$.K(d,3(i,a){4($.1p(a))c[i]=$.1p(a)});6 c}3 1k(a){4(!r.19)6 a;5 b=1g(a);6 b[b.7-1]}3 1A(q,a){4(r.1A&&(1k(u.J()).O()==q.O())&&k!=t.2e){u.J(u.J()+a.48(1k(m).7));$.D.1N(o,m.7,m.7+a.7)}};3 2k(){1I(p);p=1H(1l,47)};3 1l(){5 c=l.L();l.U();1I(p);1B();4(r.2U){u.1y(3(a){4(!a){4(r.19){5 b=1g(u.J()).17(0,-1);u.J(b.2Z(r.R)+(b.7?r.R:""))}A u.J("")}})}4(c)$.D.1N(o,o.H.7,o.H.7)};3 2V(q,a){4(a&&a.7&&s){1B();l.2T(a,q);1A(q,a[0].H);l.1W()}A{1l()}};3 1R(f,d,g){4(!r.1C)f=f.O();5 e=n.2S(f);4(e&&e.7){d(f,e)}A 4((Y r.11=="1w")&&(r.11.7>0)){5 c={45:+1E 44()};$.K(r.2R,3(a,b){c[a]=Y b=="3"?b():b});$.43({42:"41",3Z:"12"+o.3Y,2M:r.2M,11:r.11,w:$.1o({q:1k(f),3X:r.Z},c),3W:3(a){5 b=r.1r&&r.1r(a)||1r(a);n.1h(f,b);d(f,b)}})}A{l.2J();g(f)}};3 1r(c){5 d=[];5 b=c.1Z("\\n");16(5 i=0;i<b.7;i++){5 a=$.1p(b[i]);4(a){a=a.1Z("|");d[d.7]={w:a,H:a[0],M:r.1v&&r.1v(a,a[0])||a[0]}}}6 d};3 1B(){u.1e(r.21)}};$.D.1L={24:"3R",2H:"3P",21:"3O",22:1,1D:3M,1C:B,1a:C,1V:B,1j:10,Z:3K,2U:B,2R:{},1S:C,1K:3(a){6 a[0]},1q:14,1A:B,E:0,19:B,R:", ",1t:3(b,a){6 b.2C(1E 3J("(?![^&;]+;)(?!<[^<>]*)("+a.2C(/([\\^\\$\\(\\)\\[\\]\\{\\}\\*\\.\\+\\?\\|\\\\])/2A,"\\\\$1")+")(?![^<>]*>)(?![^&;]+;)","2A"),"<2z>$1</2z>")},1x:C,1s:3I};$.D.2W=3(g){5 h={};5 j=0;3 1a(s,a){4(!g.1C)s=s.O();5 i=s.3H(a);4(i==-1)6 B;6 i==0||g.1V};3 1h(q,a){4(j>g.1j){18()}4(!h[q]){j++}h[q]=a}3 1f(){4(!g.w)6 B;5 f={},2w=0;4(!g.11)g.1j=1;f[""]=[];16(5 i=0,30=g.w.7;i<30;i++){5 c=g.w[i];c=(Y c=="1w")?[c]:c;5 d=g.1q(c,i+1,g.w.7);4(d===B)1P;5 e=d.3G(0).O();4(!f[e])f[e]=[];5 b={H:d,w:c,M:g.1v&&g.1v(c)||d};f[e].1O(b);4(2w++<g.Z){f[""].1O(b)}};$.K(f,3(i,a){g.1j++;1h(i,a)})}1H(1f,25);3 18(){h={};j=0}6{18:18,1h:1h,1f:1f,2S:3(q){4(!g.1j||!j)6 14;4(!g.11&&g.1V){5 a=[];16(5 k 2G h){4(k.7>0){5 c=h[k];$.K(c,3(i,x){4(1a(x.H,q)){a.1O(x)}})}}6 a}A 4(h[q]){6 h[q]}A 4(g.1a){16(5 i=q.7-1;i>=g.22;i--){5 c=h[q.3F(0,i)];4(c){5 a=[];$.K(c,3(i,x){4(1a(x.H,q)){a[a.7]=x}});6 a}}}6 14}}};$.D.2Q=3(e,g,f,k){5 h={G:"3E"};5 j,y=-1,w,1m="",1M=C,F,z;3 2r(){4(!1M)6;F=$("<3D/>").U().P(e.2H).T("3C","3B").1J(2p.2n);z=$("<3z/>").1J(F).3y(3(a){4(V(a).2m&&V(a).2m.3w()==\'2l\'){y=$("1F",z).1e(h.G).3u(V(a));$(V(a)).P(h.G)}}).2i(3(a){$(V(a)).P(h.G);f();g.1G();6 B}).3t(3(){k.1z=C}).3s(3(){k.1z=B});4(e.E>0)F.T("E",e.E);1M=B}3 V(a){5 b=a.V;3r(b&&b.3q!="2l")b=b.3p;4(!b)6[];6 b}3 S(b){j.17(y,y+1).1e(h.G);2h(b);5 a=j.17(y,y+1).P(h.G);4(e.1x){5 c=0;j.17(0,y).K(3(){c+=I.1i});4((c+a[0].1i-z.1c())>z[0].3o){z.1c(c+a[0].1i-z.3n())}A 4(c<z.1c()){z.1c(c)}}};3 2h(a){y+=a;4(y<0){y=j.1b()-1}A 4(y>=j.1b()){y=0}}3 2g(a){6 e.Z&&e.Z<a?e.Z:a}3 2f(){z.2B();5 b=2g(w.7);16(5 i=0;i<b;i++){4(!w[i])1P;5 a=e.1K(w[i].w,i+1,b,w[i].H,1m);4(a===B)1P;5 c=$("<1F/>").3m(e.1t(a,1m)).P(i%2==0?"3l":"3k").1J(z)[0];$.w(c,"2c",w[i])}j=z.3j("1F");4(e.1S){j.17(0,1).P(h.G);y=0}4($.31.2b)z.2b()}6{2T:3(d,q){2r();w=d;1m=q;2f()},2u:3(){S(1)},2y:3(){S(-1)},2t:3(){4(y!=0&&y-8<0){S(-y)}A{S(-8)}},2s:3(){4(y!=j.1b()-1&&y+8>j.1b()){S(j.1b()-1-y)}A{S(8)}},U:3(){F&&F.U();j&&j.1e(h.G);y=-1},L:3(){6 F&&F.3i(":L")},3h:3(){6 I.L()&&(j.2a("."+h.G)[0]||e.1S&&j[0])},1W:3(){5 a=$(g).3g();F.T({E:Y e.E=="1w"||e.E>0?e.E:$(g).E(),2E:a.2E+g.1i,1Q:a.1Q}).1W();4(e.1x){z.1c(0);z.T({29:e.1s,3e:\'3d\'});4($.1T.3b&&Y 2p.2n.3T.29==="3a"){5 c=0;j.K(3(){c+=I.1i});5 b=c>e.1s;z.T(\'3V\',b?e.1s:c);4(!b){j.E(z.E()-28(j.T("32-1Q"))-28(j.T("32-39")))}}}},26:3(){5 a=j&&j.2a("."+h.G).1e(h.G);6 a&&a.7&&$.w(a[0],"2c")},2J:3(){z&&z.2B()},1u:3(){F&&F.37()}}};$.D.1N=3(b,a,c){4(b.2O){5 d=b.2O();d.36(C);d.35("2P",a);d.4c("2P",c);d.4b()}A 4(b.2Y){b.2Y(a,c)}A{4(b.2X){b.2X=a;b.4a=c}}b.1G()}})(49);',62,261,'|||function|if|var|return|length|||||||||||||||||||||||||data||active|list|else|false|true|Autocompleter|width|element|ACTIVE|value|this|val|each|visible|result|break|toLowerCase|addClass|case|multipleSeparator|moveSelect|css|hide|target|onChange|bind|typeof|max||url|autocomplete||null|trigger|for|slice|flush|multiple|matchSubset|size|scrollTop|preventDefault|removeClass|populate|trimWords|add|offsetHeight|cacheLength|lastWord|hideResultsNow|term|arguments|extend|trim|formatMatch|parse|scrollHeight|highlight|unbind|formatResult|string|scroll|search|mouseDownOnSelect|autoFill|stopLoading|matchCase|delay|new|li|focus|setTimeout|clearTimeout|appendTo|formatItem|defaults|needsInit|Selection|push|continue|left|request|selectFirst|browser|selectCurrent|matchContains|show|unautocomplete|setOptions|split|flushCache|loadingClass|minChars|findValueCallback|inputClass||selected||parseInt|maxHeight|filter|bgiframe|ac_data|COMMA|BACKSPACE|fillList|limitNumberOfItems|movePosition|click|PAGEUP|hideResults|LI|nodeName|body|PAGEDOWN|document|ESC|init|pageDown|pageUp|next|RETURN|nullData|TAB|prev|strong|gi|empty|replace|DEL|top|keyCode|in|resultsClass|DOWN|emptyList|form|opera|dataType|UP|createTextRange|character|Select|extraParams|load|display|mustMatch|receiveData|Cache|selectionStart|setSelectionRange|join|ol|fn|padding|||moveStart|collapse|remove||right|undefined|msie|off|auto|overflow|attr|offset|current|is|find|ac_odd|ac_even|html|innerHeight|clientHeight|parentNode|tagName|while|mouseup|mousedown|index|blur|toUpperCase|188|mouseover|ul|default|absolute|position|div|ac_over|substr|charAt|indexOf|180|RegExp|100|switch|400|keydown|ac_loading|ac_results|keypress|ac_input|submit|style|150|height|success|limit|name|port||abort|mode|ajax|Date|timestamp||200|substring|jQuery|selectionEnd|select|moveEnd'.split('|'),0,{})) \ 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 00000000..fe8c976a
--- /dev/null
+++ b/modules/server_add/js/server_add.js
@@ -0,0 +1,131 @@
+$("#gServerAdd").ready(function() {
+ $("#gServerAdd :submit").click(function(event) {
+ do_add(this, event);
+ });
+ $("#gProgressBar").progressbar();
+ $("#gServerAdd ul").css("display", "block");
+});
+
+function open_close_branch(icon, event) {
+ var parent = icon.parentNode;
+ var children = $(parent).find(".gCheckboxTree");
+ var closed = $(icon).hasClass("ui-icon-plus");
+
+ if (closed) {
+ if (children.length == 0) {
+ load_children(icon, function(data, textStatus) {
+ $(parent).append(data);
+ $(icon).addClass("ui-icon-minus");
+ $(icon).removeClass("ui-icon-plus");
+ var checkbox = $(parent).find(":checkbox")[0];
+ checkbox_click(checkbox, null);
+ });
+ } else {
+ $(icon).addClass("ui-icon-minus");
+ $(icon).removeClass("ui-icon-plus");
+ }
+ $(parent).children("ul").slideDown("fast");
+ } else {
+ $(icon).addClass("ui-icon-plus");
+ $(icon).removeClass("ui-icon-minus");
+ $(parent).children("ul").slideUp("fast");
+ }
+}
+
+function checkbox_click(checkbox, event) {
+ var parents = $(checkbox).parents("li");
+ var parent = parents.get(0);
+ $(parent).find(".gCheckboxTree :checkbox").attr("checked", checkbox.checked);
+ var checked = $("#gServerAdd :checkbox[checked]");
+ $("#gServerAdd form :submit").attr("disabled", checked.length == 0);
+}
+
+function load_children(icon, callback) {
+ var csrf = $("#gServerAdd form :hidden[name='csrf']")[0].value;
+ var base_url = $("#gServerAdd form :hidden[name='base_url']")[0].value;
+ var parms = "&csrf=" + csrf;
+ var parents = $(icon).parents("li");
+ for (var i=parents.length - 1; i >= 0; i--) {
+ parms += "&path[]=" + $(parents[i]).children("span").attr("ref");
+ }
+ $.ajax({async: false,
+ success: callback,
+ data: parms,
+ dataType: "html",
+ type: "POST",
+ url: base_url + "server_add/children"
+ });
+}
+
+var current = 0;
+var process_length = 0;
+function do_add(submit, event) {
+ event.preventDefault();
+ $("#gProgressBar").progressbar("value", 0);
+ $("#gProgressBar").css("visibility", "visible");
+ var check_list = $("#gServerAdd :checkbox[checked]");
+ process_length = check_list.length;
+ current = 0;
+ var base_url = $("#gServerAdd form :hidden[name='base_url']")[0].value;
+ $.ajax({async: false,
+ dataType: "json",
+ type: "POST",
+ url: base_url + "server_add/start"
+ });
+ $.each(check_list, function () {
+ process_checkbox(this);
+ });
+ $.ajax({async: false,
+ success: function(data, textStatus) {
+ document.location.reload();
+ },
+ dataType: "json",
+ type: "POST",
+ url: base_url + "server_add/finish"
+ });
+ return false;
+}
+
+function process_checkbox(checkbox) {
+ var parents = $(checkbox).parents("li");
+ var csrf = $("#gServerAdd form :hidden[name='csrf']")[0].value;
+ var parms = "&csrf=" + csrf;
+ for (var i=parents.length - 1; i > 0; i--) {
+ parms += "&path[]=" + $(parents[i]).children("span").attr("ref");
+ }
+ parms += "&path[]=" + $(checkbox).val();
+
+ var parent = parents[0];
+ if ($(parent).hasClass("gFile")) {
+ process_file(parents[0], parms);
+ } else if ($(parent).hasClass("gDirectory") && $(parents[0]).find(".gCheckboxTree").length == 0) {
+ // If it is a directory and retrieve the children and process them
+ var icon = $(parent).children("span")[0];
+ load_children(icon, function(data, textStatus) {
+ $(parent).append(data);
+ $(icon).addClass("ui-icon-plus");
+ checkbox_click(checkbox, null);
+ var boxes = $(parent).find(".gCheckboxTree :checkbox[checked]");
+ process_length += boxes.length;
+ $.each(boxes, function () {
+ process_checkbox(this);
+ });
+ });
+ current++;
+ $("#gProgressBar").progressbar("value", current / process_length * 100);
+ }
+}
+
+function process_file(li_element, parms) {
+ $.ajax({async: false,
+ success: function(data, status) {
+ },
+ data: parms,
+ dataType: "html",
+ type: "POST",
+ url: $("#gServerAdd form").attr("action")
+ });
+ current++;
+ $("#gProgressBar").progressbar("value", current / process_length * 100);
+}
+
diff --git a/modules/server_add/module.info b/modules/server_add/module.info
new file mode 100644
index 00000000..3b0dce31
--- /dev/null
+++ b/modules/server_add/module.info
@@ -0,0 +1,3 @@
+name = Add from Server
+description = Allows authorized users to load images from the local server
+version = 1
diff --git a/modules/server_add/views/server_add_admin.html.php b/modules/server_add/views/server_add_admin.html.php
new file mode 100644
index 00000000..765feeb9
--- /dev/null
+++ b/modules/server_add/views/server_add_admin.html.php
@@ -0,0 +1,10 @@
+<?php defined("SYSPATH") or die("No direct script access.") ?>
+<div id="gServerAddAdmin">
+ <h2>
+ <?= t("Add From Server Admininstration") ?>
+ </h2>
+ <div id="gAuthorizedPath">
+ <?= $path_list ?>
+ </div>
+ <?= $add_form ?>
+</div>
diff --git a/modules/server_add/views/server_add_dir_list.html.php b/modules/server_add/views/server_add_dir_list.html.php
new file mode 100644
index 00000000..762b1a4d
--- /dev/null
+++ b/modules/server_add/views/server_add_dir_list.html.php
@@ -0,0 +1,13 @@
+<?php defined("SYSPATH") or die("No direct script access.") ?>
+<span><?= t("Authorized Paths") ?></span>
+<ul id="gPathList">
+ <? foreach ($paths as $id => $path): ?>
+ <li class="ui-icon-left">
+ <span id="icon_<?= $id?>" class="gRemoveDir ui-icon ui-icon-trash"></span>
+ <?= $path ?>
+ </li>
+ <? endforeach ?>
+</ul>
+<div id="gNoAuthorizedPaths" <? if (!empty($paths)): ?>style="display:none"<? endif ?>>
+ <span class="gWarning"><?= t("No Authorized image source paths defined") ?></span>
+</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 00000000..b664c679
--- /dev/null
+++ b/modules/server_add/views/server_add_tree.html.php
@@ -0,0 +1,22 @@
+<?php defined("SYSPATH") or die("No direct script access.") ?>
+<script type="text/javascript">
+$("#<?= $uid ?>").ready(function() {
+ $("#<?= $uid ?> span.ui-icon").click(function(event) {
+ open_close_branch(this, event);
+ });
+
+ $("#<?= $uid ?> :checkbox").click(function(event) {
+ checkbox_click(this, event);
+ });
+});
+</script>
+<ul id="<?= $uid ?>" class="gCheckboxTree">
+ <? foreach ($data as $file => $file_info): ?>
+ <li class="<?= empty($file_info["is_dir"]) ? "gFile" : "gDirectory gCollapsed ui-icon-left" ?>">
+ <? if (!empty($file_info["is_dir"])): ?>
+ <span class="ui-icon ui-icon-plus" ref="<?= $file ?>"></span>
+ <? endif ?>
+ <label> <?= form::checkbox("checkbox", $file) . " $file" ?> </label>
+ </li>
+ <? endforeach ?>
+</ul>
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 00000000..26286e05
--- /dev/null
+++ b/modules/server_add/views/server_add_tree_dialog.html.php
@@ -0,0 +1,26 @@
+<?php defined("SYSPATH") or die("No direct script access.") ?>
+<link media="screen, projection" rel="stylesheet" type="text/css"
+ href="<?= url::file("modules/server_add/css/server_add.css") ?>" />
+<?= html::script("modules/server_add/js/server_add.js"); ?>
+
+<div id="gServerAdd">
+ <h1 style="display: none;"><?= sprintf(t("Add Photos to '%s'"), $album_title) ?></h1>
+
+ <p id="gDescription"><?= t("Photos will be added to album:") ?></p>
+ <ul class="gBreadcrumbs">
+ <? foreach ($parents as $parent): ?>
+ <li><?= $parent->title ?></li>
+ <? endforeach ?>
+ <li class="active"><?= $album_title ?></li>
+ </ul>
+
+ <?= form::open($action, array("method" => "post"), $hidden) ?>
+ <div id="gServerAddTree" >
+ <?= $tree ?>
+ </div>
+ <span>
+ <?= form::submit(array("id" => "gServerAddButton", "name" => "add", "disabled" => true, "class" => "submit"), t("Add")) ?>
+ </span>
+ <?= form::close() ?>
+ <div id="gProgressBar" ></div>
+</div>